﻿using ConfExpert.Utility;
using DevExpress.XtraReports.UI;
using DevTeam;
using System;
using System.Data;

namespace ConfExpert.Forms.Rapor
{
    public partial class xrCekmeDegerleri : DevExpress.XtraReports.UI.XtraReport
    {
        DataSet ds { get; set; }
        string tip = string.Empty;

        public xrCekmeDegerleri(string idx, string tip)
        {
            this.tip = tip;
            InitializeComponent();

            ds = Session.DataManager.ExecuteDataSet("GetCekmeDegerleri", idx);

            xrSubCekmeDegerleri srCekmeDegerleri = (xrSubCekmeDegerleri)SubCekmeDegerleri.ReportSource;
            srCekmeDegerleri.fillTable(ds.Tables[1]);

            BindDstoReport();
        }


        void BindDstoReport()
        {
            this.DataSource = ds;
            this.DataMember = "Table";


            tcOlusturan.Text = AppSession.Lookups.V_User.FindByUserId(Session.CurrentUser.UserId).Name;
            tcOlusturulmaTarihi.Text = DateTime.Now.ToShortDateString();

            xrPicture.DataBindings.Add("Image", null, "Table.Photo3");
            tcProduct.DataBindings.Add("Text", null, "Table.Product");
            tcMusteri.DataBindings.Add("Text", null, "Table.Musteri");
            tcUretici.DataBindings.Add("Text", null, "Table.Uretici");

            switch (tip)
            {
                case "Yıkama":
                    tcYikamaRecetesi.DataBindings.Add("Text", null, "Table.YikamaRecetesi");
                    xrTableCell3.Text = "Yıkama Reçetesi";
                    tcHeader.Text = "Yıkama Testi Sonucu";
                    break;

                case "Ütü":
                    tcYikamaRecetesi.DataBindings.Add("Text", null, "Table.UtuBilgisi");
                    xrTableCell3.Text = "Ütü Bilgisi";
                    tcHeader.Text = "Ütü Testi Sonucu";
                    break;
            }

            //tcNotlar.Text = drHeader["TestNotu"].ToString();

        }

        private void SubCekmeDegerleri_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            ((xrSubCekmeDegerleri)SubCekmeDegerleri.ReportSource).PrdId.Value = GetCurrentColumnValue("ProductId").ToInt();
        }

        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Detail.HeightF = tbSub.HeightF = xrTable12.HeightF = 240F;
        }

        private void xrTable12_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Detail.HeightF = tbSub.HeightF = xrTable12.HeightF = 240F;

            int a = ds.Tables["Table1"].Select("ProductId=" + GetCurrentColumnValue("ProductId").ToString()).Length;
            if (a > 3)
            {
                xrTable12.HeightF = a * 80;
            }
        }

        private void tbSub_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            Detail.HeightF = tbSub.HeightF  = 240F;

            int a = ds.Tables["Table1"].Select("ProductId=" + GetCurrentColumnValue("ProductId").ToString()).Length;
            if (a > 3)
            {
                tbSub.HeightF = a * 80;
            }
        }
    }
}
